<table id="card_recharge_info" data-options="fit:true"></table>
<div id="recharge_toolbar" style="padding:0 10px;">
	<input class="icon-add" type="button" value="充值" onclick="javascript:openRechargeWin()"
		style="padding-left:20px;border:1px #999 solid;margin:2px;"/>
	<input class="icon-reload" type="button" value="刷新" onclick="javascript:flushRecharge()"
		style="padding-left:20px;border:1px #999 solid;margin:2px;"/>
	<div style="float:right;margin-right:20px;">
		查询条件：
		<select id="rec_myselect" style="text-align:center;">
			<option value="null">-- 请选择 --</option>
			<option value="卡号">卡号</option>
			<option value="状态">是否充值成功</option>
		</select>
		<input style="text-align:center;" type="text" id="rec_input_text">
		<input type="button" value="查询" onclick="javascript:findRecharge()"/>
	</div>
</div>

<script>
$(function(){
	$('#card_recharge_info').datagrid({
		url:'../cardInfoServlet?t='+new Date(),
		queryParams:{op:"getRechargeInfo"},
		loadMsg:'数据加载中...',
		fitColumns:true,
		rownumbers:true,
		striped:true,
		sortName:'rid',
		sortOrder:'asc',
		remoteSort:false,
		columns:[[
			{field:'rid',title:'充值编号',width:100,align:'center',sortable:true},
			{field:'sid',title:'校园卡编号',width:100,align:'center'}, 
			{field:'rmoney',title:'充值金额',width:100,align:'center'},
			{field:'rtime',title:'充值时间',width:100,align:'center'},
			{field:'rstatus',title:'是否充值成功',width:100,align:'center',formatter:function(value,rowData,rowIndex){
				if(value == 1) {
					return "充值成功";
				} else {
					return "充值失败";
				}
			}}
		]],
		toolbar:"#recharge_toolbar"
	});
});

function flushRecharge(){
	$('#card_recharge_info').datagrid("reload");
}

//充值
function addRechargeInfo(){
	var sid = $.trim($("#sid").val());          
	var studentId = $.trim($("#studentId_recharge").val());
	var rmoney = $.trim($("#rmoney").val());
	
	//为空判断
	if(rmoney!="" && studentId!="" && sid!="") {
		$.post("../cardInfoServlet?t="+new Date(),
			{op:"rechargeMoney",sid:sid,rmoney:rmoney},
			function(data){
			data = parseInt($.trim(data));
			if(data > 0) {
				$.messager.show({
					title:'成功提示',
					msg:'充值成功!',
					timeout:3000,
					showType:'slide'
				});
				$("#sid").val("");
				$("#studentId_recharge").val("");
				$("#recharge_sname").val("");
				$("#recharge_sclass").val("");
				$("#recharge_sdepartment").val("");
				$("#recharge_rmoney").val("");
				
				$("#add_recharge_data").dialog("close");
				$('#card_recharge_info').datagrid("reload");
			} else {
				$.messager.alert('错误提示','学生信息添加失败!','error');
			}
		});
	} else {
		$.messager.show({
			title:'温馨提示',
			msg:'您输入的信息不完整，请确认后再提交!',
			timeout:3000,
			showType:'slide'
		});
	}
}

function findRecharge() {
	var myselect = $.trim($("#rec_myselect").val());
	var info=$.trim($("#rec_input_text").val());
	if (myselect != "null" && info != "") {
		$.post("../cardInfoServlet?t="+new Date(),{op:"findRecInfo",myselect:myselect,info:info},function(data){
			if(parseInt($.trim(data))==0){
				$.messager.alert('错误提示','没有该信息!','error');
			}
			if(data!=null){
				$('#card_recharge_info').datagrid("loadData",data.rows);
			} else {
				$.messager.alert('错误提示','没有该信息!','error');
			}
		},"json");
	}else{
		$.messager.show({
			title : '温馨提示',
			msg : '您输入的信息不完整，请确认后再提交!',
			timeout : 3000,
			showType : 'slide'
		});
	}
}

function openRechargeWin() {
	$("#add_recharge_data").dialog("open");
	if(sid!=null) {
		$("#sid").blur(function(){
			var sid = $.trim($("#sid").val());
			$.post("../cardInfoServlet?t="+new Date(),{op:"getSidInfo",sid:sid},function(data){
				if(parseInt($.trim(data))==0){
					$.messager.alert('错误提示','没有该信息!','error');
				}else{
					//console.info(data.sidInfo[0].sname+" "+data.sidInfo[0].sclass+" "+data.sidInfo[0].sdepartment);
					$("#studentId_recharge").val(data.sidInfo[0].studentId);
					$("#recharge_sname").val(data.sidInfo[0].sname);
					$("#recharge_sclass").val(data.sidInfo[0].sclass);
					$("#recharge_sdepartment").val(data.sidInfo[0].sdepartment);
				}
			},"json");
		});
	}else{
		$.messager.show({
			title : '温馨提示',
			msg : '输入有误!',
			timeout : 3000,
			showType : 'slide'
		});
	}
}
</script>
<div id="add_recharge_data" class="easyui-dialog" title="充值" style="width:400px;height:350px;"
	data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
	<p style="width:100%;text-align:center;">
		<br /> <br /> 
		<label for="sid">卡号：</label><input type="text" id="sid">
		<br /> <br /> 
		<label for="studentId_recharge">学号：</label><input type="text" id="studentId_recharge" disabled="disabled">
		<br /> <br /> 
		<label for="sname">姓名：</label><input type="text" id="recharge_sname" disabled="disabled" >
		<br /> <br />
		<label for="sclass">班级：</label><input type="text" id="recharge_sclass" disabled="disabled" >
		<br /> <br />
		<label for="sdepartment">学院：</label><input type="text" id="recharge_sdepartment" disabled="disabled" >
		<br /> <br />
		<label for="rmoney">充值金额：</label><input type="text" id="recharge_rmoney">
		<br /> <br />
		<input style="padding:5px 25px;" type="button" onclick="addRechargeInfo()" value="充值">
	</p>
</div>

